home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / ada_tutr.zip / TXT2DAT.ADA < prev    next >
Text File  |  1991-03-25  |  2KB  |  52 lines

  1. -- TXT2DAT.ADA   Ver. 2.00   25-MAR-1991   Copyright 1988-1991 John J. Herro
  2. -- Software Innovations Technology
  3. -- 1083 Mandarin Drive NE, Palm Bay, FL  32905-4706   (407)951-0233
  4. --
  5. -- After running DAT2TXT on a PC and transferring the resulting TUTOR.TXT
  6. -- file to another computer, compile and run this program on the other
  7. -- computer to create ADA_TUTR.DAT on that machine.
  8. --
  9. with DIRECT_IO, TEXT_IO;
  10. procedure TXT2DAT is
  11.    subtype BLOCK_SUBTYPE is STRING(1 .. 64);
  12.    package RANDOM_IO is new DIRECT_IO(BLOCK_SUBTYPE);
  13.    TEXT_FILE  : TEXT_IO.FILE_TYPE;                           -- The input file.
  14.    DATA_FILE  : RANDOM_IO.FILE_TYPE;                        -- The output file.
  15.    OK         : BOOLEAN := TRUE;     -- True when both files open successfully.
  16.    INPUT      : STRING(1 .. 65);           -- Line of text read from TUTOR.TXT.
  17.    LEN        : INTEGER;                 -- Length of line read from TUTOR.TXT.
  18.    LEGAL_NOTE : constant STRING := " Copyright 1988-91 John J. Herro ";
  19.                        -- LEGAL_NOTE isn't used by the program, but it causes
  20.                        -- most compilers to place this string in the .EXE file.
  21. begin
  22.    begin
  23.       TEXT_IO.OPEN(TEXT_FILE, MODE => TEXT_IO.IN_FILE, NAME => "TUTOR.TXT");
  24.    exception
  25.       when TEXT_IO.NAME_ERROR =>
  26.          TEXT_IO.PUT_LINE(
  27.               "I'm sorry.  The file TUTOR.TXT seems to be missing.");
  28.          OK := FALSE;
  29.    end;
  30.    begin
  31.       RANDOM_IO.CREATE(DATA_FILE, RANDOM_IO.OUT_FILE, NAME => "ADA_TUTR.DAT");
  32.    exception
  33.       when others =>
  34.          TEXT_IO.PUT_LINE("I'm sorry.  I can't seem to create ADA_TUTR.DAT.");
  35.          TEXT_IO.PUT_LINE("Perhaps that file already exists?");
  36.          OK := FALSE;
  37.    end;
  38.    if OK then
  39.       while not TEXT_IO.END_OF_FILE(TEXT_FILE) loop
  40.          TEXT_IO.GET_LINE(FILE => TEXT_FILE, ITEM => INPUT, LAST => LEN);
  41.          if LEN > 3 then  -- In case extra CRs/LFs were added to the text file.
  42.             INPUT(LEN + 1 .. 64) := (others => ' ');
  43.               -- In case trailing blanks were lost when transferring TUTOR.TXT.
  44.             RANDOM_IO.WRITE(DATA_FILE, ITEM => INPUT(1 .. 64));
  45.          end if;
  46.       end loop;
  47.       TEXT_IO.CLOSE(TEXT_FILE);
  48.       RANDOM_IO.CLOSE(DATA_FILE);
  49.       TEXT_IO.PUT_LINE("ADA_TUTR.DAT created.");
  50.    end if;
  51. end TXT2DAT;
  52.